export const dateCalculator = function (){
	
	//计算两个时间相差的天数（精度到0.00）
	function daysBetweenPrecision(beginDate, endDate) {
		let begin = new Date(beginDate)
		let end = new Date(endDate);
		let t1 = begin.getTime();
		let t2 = end.getTime();
		let dayTime = 1000 * 60 * 60 * 24; //每一天的毫秒数
		// console.log('t1',t1)
		// console.log('t2',t2)
		// console.log('dayTims:',dayTime)
		let minusDays = (t2 - t1) / dayTime;//两个时间相差的天数
		// console.log('minusDays',minusDays)
		return Math.floor(minusDays*100)/100;//保留两位小数
		// console.log('days',days)
		// return Math.abs(days);//最后去结果的绝对值
	}
	// console.log('precision',daysBetweenPrecision('2014-10-1 10:20','2014-10-7'))
	// console.log('between',daysBetween('2014-10-1 10:20','2014-10-7'))

	//计算两个时间相差的天数（包含结束日期，若不足一天向上取整）。
	function daysBetween(beginDate, endDate){
		let days = daysBetweenPrecision(beginDate,endDate)
		return Math.ceil(days);
	}
	
	return {
		daysBetween,
		daysBetweenPrecision,
	}
}()

